package com.ruoyi.order.station.transform;

import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.order.bo.ProductBarcode;
import com.ruoyi.order.domain.MesDetectNode;
import com.ruoyi.order.enums.BarcodeTypeEnum;
import com.ruoyi.order.station.request.instance.*;

import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;

public class BarcodeProductDataTrans {

    /**
     * 将生产数据中的各类物料码，识别码提取
     *
     * @param detectNode
     * @param obj1
     * @param obj2
     */
    public static List<ProductBarcode> handleProductBarcode(String modelCode, MesDetectNode detectNode, String partNumber, Object obj1, Object obj2) {
        List<ProductBarcode> productBarcodeList = new ArrayList<>();
        if (detectNode.getNodeCode().equals("1")) {
            OP01Data op1Data = (OP01Data) obj1;
            ProductBarcode barcode1 = new ProductBarcode();
            String qrCode1 = new String(op1Data.getIgbtMaterialNo(), StandardCharsets.UTF_8);
            barcode1.setBarcode(StringUtils.trim(qrCode1));
            barcode1.setBarcodeType(BarcodeTypeEnum.igbtMaterialNo.getCode());
            barcode1.setModelCode(modelCode);
            barcode1.setPartNumber(partNumber);
            barcode1.setStationCode(detectNode.getNodeCode());
            productBarcodeList.add(barcode1);
            ProductBarcode barcode2 = new ProductBarcode();
            String qrCode2 = new String(op1Data.getDriverBoardPCBMaterialNo(), StandardCharsets.UTF_8);
            barcode2.setBarcode(StringUtils.trim(qrCode2));
            barcode2.setBarcodeType(BarcodeTypeEnum.driverBoardPCBMaterialNo.getCode());
            barcode2.setModelCode(modelCode);
            barcode2.setPartNumber(partNumber);
            barcode2.setStationCode(detectNode.getNodeCode());
            productBarcodeList.add(barcode2);
            ProductBarcode barcode3 = new ProductBarcode();
            String qrCode3 = new String(op1Data.getScrewBatchNo(), StandardCharsets.UTF_8);
            barcode3.setBarcode(StringUtils.trim(qrCode3));
            barcode3.setBarcodeType(BarcodeTypeEnum.screwBatchNo.getCode());
            barcode3.setModelCode(modelCode);
            barcode3.setPartNumber(partNumber);
            barcode3.setStationCode(detectNode.getNodeCode());
            productBarcodeList.add(barcode3);
        }
        if (detectNode.getNodeCode().equals("29")) {
            OP29Data op29Data = (OP29Data) obj1;
            ProductBarcode barcode1 = new ProductBarcode();
            barcode1.setBarcode(String.valueOf(op29Data.getTraceCode()));
            barcode1.setBarcodeType(BarcodeTypeEnum.traceCode.getCode());
            barcode1.setModelCode(modelCode);
            barcode1.setPartNumber(partNumber);
            barcode1.setStationCode(detectNode.getNodeCode());
            productBarcodeList.add(barcode1);
        }
        return productBarcodeList;
    }
}